package com.byit.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.byit.domain.AppUser;
import com.byit.domain.SysUser;
import com.byit.mapper.AppUserMapper;
import com.byit.service.IAppUserService;
import com.byit.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wangx
 * @since 2019-01-03
 */
@Service
public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> implements IAppUserService {

    @Autowired
    private AppUserMapper appUserMapper;

    @Override
    public AppUser selectByPhone(String phone) {
        return appUserMapper.selectByPhone(phone);
    }

    @Override
    public void updatePwdByPhone(Map<String, Object> params) {
        appUserMapper.updatePwdByPhone(params);
    }

    @Override
    public JSONObject getUserInfo(Long userId) {
        JSONObject appUser = appUserMapper.getUserInfo(userId);
        return appUser;
    }

    @Override
    public AppUser selectByAnonymous(String anonymous) {
        AppUser user = appUserMapper.selectByAnonymous(anonymous);
        return user;
    }

    @Override
    public void updateAnonymous(Long userId, String anonymous) {
        appUserMapper.updateAnonymous(userId,anonymous);
    }

    @Override
    public void updateSignature(Long userId, String signature) {
        appUserMapper.updateSignature(userId,signature);
    }

    @Override
    public void updatePassword(Map<String, Object> params) {
        appUserMapper.updatePassword(params);
    }

    @Override
    public void updateAvatar(Map<String, Object> params) {
        appUserMapper.updateAvatar(params);
    }

    @Override
    public void updateMobile(Map<String, Object> params) {
        appUserMapper.updateMobile(params);
    }

    @Override
    public void updateDelete(Map<String, Object> params) {
        appUserMapper.updateDelete(params);
    }

    @Override
    public void updateLoss(Map<String, Object> params) {
        appUserMapper.updateLoss(params);
    }

    @Override
    public void updateRestore(Map<String, Object> params) {
        appUserMapper.updateRestore(params);
    }

    @Override
    public Page<JSONObject> selectUserList(Page<SysUser> pageInfo, Map<String, Object> params) {
        List<JSONObject> list = appUserMapper.selectUserList(pageInfo,params);
        Page<JSONObject> page = PageUtil.transform(pageInfo);
        page.setRecords(list);
        return page;
    }

    @Override
    public List<JSONObject> selectAllUserPhone() {
        return appUserMapper.selectAllUserPhone();
    }

    @Override
    public AppUser selectByPhoneOrIdCode(String account) {
        return appUserMapper.selectByPhoneOrIdCode(account);
    }
}
